/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation
**
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
**     the names of its contributors may be used to endorse or promote
**     products derived from this software without specific prior written
**     permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
** $QT_END_LICENSE$
**
****************************************************************************/


//import Qt 4.7


import QtQuick 1.0
import com.nokia.symbian 1.0

//main application window
ApplicationWindow {
    id: window

    function setStateIfFound(target, name) {
        for (var i = 0; i < target.states.length; i++) {
            var curState = target.states[i];
            if(curState.name == name) {
                target.state = name
                break
            }
        }
    }


    ToolBarLayout {
        id: commonTools

        ToolButton {
            flat: true
            iconSource: "qrc:/qtg_toolbar_back.svg"
            onClicked: pageStack.depth <= 1 ? Qt.quit() : pageStack.pop()
        }

        ToolButton {
            flat: true
            iconSource: "qrc:/qtg_toolbar_options.svg"
            onClicked:
            {
                 viewMenu.open()
            }
        }
    }

    Page {
        id: page
        anchors.fill: parent

        tools: commonTools
        Component.onCompleted: {
            if(screen.currentOrientation == Screen.Portrait) {
                setStateIfFound(page, "PortraitState")
            } else if(screen.currentOrientation == Screen.Landscape) {
                setStateIfFound(page, "LandscapeState")
            }
        }

        Rectangle{
            id:rect
            anchors.fill: parent
            color:"grey"
        }
        PageHeading{
            id: heading
            anchors.top: parent.top
            width: parent.width
            text: qsTr("Phone Utility")
            fontItalic:true
        }

        Text {// Label; is centralized horizontally
            id: textLabel
            width: 80
            height: 20
            color: "#845717"
            text: ""
            anchors.horizontalCenter: parent.horizontalCenter
            visible: false
            horizontalAlignment: Text.AlignHCenter
            opacity: 0.9
            styleColor: "#e00e0e"
            font.pixelSize: 24
            }

        Text {//the text used to display information as per the states
            id: textDisplay
            width: page.width
            height: 35
            color: "#c62626"
            text: ""
            visible: false
            font.bold: true
            horizontalAlignment: TextInput.AlignHCenter
            font.pixelSize: 20
            anchors.horizontalCenter: page.horizontalCenter
            }

        Text { // phone model display text.
            id: textModel
            width: page.width
            height: 35
            color: "#c62626"
            text: ""
            font.pixelSize: 20
            anchors.horizontalCenter: page.horizontalCenter
            visible: false
            font.bold: true
            horizontalAlignment: TextInput.AlignHCenter
            }

        Text { // phone IMEI number display text.
            id: textIMEI
            width: page.width
            height: 35
            color: "#c62626"
            text: ""
            font.pixelSize: 20
            anchors.horizontalCenter: page.horizontalCenter
            visible: false
            font.bold: true
            horizontalAlignment: TextInput.AlignHCenter
            }


        ProgressBar {
            id: batteryStrength
            width: page.width - 100
            x: 60
            visible:  false
        }



        Menu{
            id: viewMenu

                content:
                Column{
                MenuItem {
                    text: "BatteryInfo"

                    onClicked:
                    {
                        page.state = "BatteryInfo";
                        batteryStrength.value = systemModel.returnMessage();
                        viewMenu.close()
                    }
                }
                MenuItem { text: "Indicator"
                    onClicked:
                    {
                        page.state = "Indicator";
                        textDisplay.text = systemModel1.returnMessage();
                        viewMenu.close()
                    }
                }
                MenuItem { text: "PhoneInfo"
                    onClicked:
                    {
                        page.state = "PhoneInfo"
                        textDisplay.text = systemModel2.returnMessagePhone();
                        textModel.text = systemModel2.returnMessageModel();
                        textIMEI.text = systemModel2.returnMessageSerialNumber();
                        viewMenu.close()
                    }
                }

            }

        }


        // set of states defined to cover the use cases.
        // showing BatteryInfo, Indicator and PhoneInfo.
            states: [
                State {
                    name: "BatteryInfo"
                    PropertyChanges {
                        target: textLabel
                        text: "Battery Strength"
                        visible: true
                        y: ((window.height /2) - 50)
                    }


                    PropertyChanges {
                        target: textDisplay
                        y: ((window.height /2) + 10)
                        color: "#2638c6"
                        visible: false
                    }
                    PropertyChanges {
                        target: textModel
                        visible: false
                    }
                    PropertyChanges {
                        target: textIMEI
                        visible: false
                    }

                    PropertyChanges {
                        target: batteryStrength
                        visible:  true
                        //value: systemModel.returnMessage();
                        y: ((window.height /2) + 10)
                        NumberAnimation on value { from: 0; to: systemModel.returnMessage(); loops: Animation.Infinite }
                    }
                },
                State {
                    name: "Indicator"
                    PropertyChanges {
                        target: textLabel
                        text: "Indicator Status"
                        visible: true
                        y: ((window.height /2) - 50)
                    }

                    PropertyChanges {
                        target: textDisplay
                        y: ((window.height /2) + 10)
                        color: "#2638c6"
                        visible: true
                    }
                    PropertyChanges {
                        target: textModel
                        visible: false
                    }
                    PropertyChanges {
                        target: textIMEI
                        visible: false
                    }

                    PropertyChanges {
                        target: batteryStrength
                        visible: false
                    }

                },
                State {
                    name: "PhoneInfo"
                    PropertyChanges {
                        target: textLabel
                        text: "Phone Info"
                        visible: true
                        y: ((window.height /2) - 110)
                    }

                    PropertyChanges {
                        target: textDisplay
                        y: ((window.height /2) - 70)
                        color: "#2638c6"
                        visible: true
                    }
                    PropertyChanges {
                        target: textModel
                        visible: true
                        y: ((window.height /2) - 20)
                        color: "#2638c6"
                    }
                    PropertyChanges {
                        target: textIMEI
                        visible: true
                        y: ((window.height /2) + 30)
                        color: "#2638c6"
                    }

                    PropertyChanges {
                        target: batteryStrength
                        visible: false
                    }
                }
            ]



    }

    Component.onCompleted: pageStack.push(page)
}

